package com.ruifu.doc.service.impl;

import com.fhzncloud.cloud.common.security.service.CloudUser;
import com.ruifu.common.config.CodeType;
import com.ruifu.common.utils.ProjectCodeUtils;
import com.ruifu.doc.mapper.DmDocMasterMapper;
import com.ruifu.doc.service.DmDocMasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author nyr
 * @create 2019/9/9
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DmDocMasterServiceImpl implements DmDocMasterService {

    /**
     * 文档mapper对象
     */
    @Autowired(required = false)
    private DmDocMasterMapper dmDocMasterMapper;

    /**
     * 根据文档代号查询是否存在
     *
     * @param dmDocCode 文档代号
     * @param cloudUser
     * @return
     */
    @Override
    public Boolean findByDmDocCode(String dmDocCode, CloudUser cloudUser) {
        return dmDocMasterMapper.findByDmDocCode(dmDocCode, cloudUser) == null;
    }

    /**
     * 获取文档编号
     *
     * @param count
     * @return
     */
    @Override
    public List<String> getDocCode(Integer count) {
        List<String> codeList = new ArrayList<>();
        for (Integer i = 0; i < count; i++) {
            codeList.add(ProjectCodeUtils.getCode(CodeType.DOCUMENT));
        }
        return codeList;
    }
}
